package 链表.easy;

import 链表.middle.ShiJiu;

/**
 * @author Lw中
 * @date 2020/9/23 15:05
 */
public class ErLingLu {

    class ListNode {
        int val;
        ListNode next;
        ListNode(int x) {
            val = x;
            next = null;
        }
    }

    /**
     * 反转链表
     * @param head
     * @return
     */
    public ListNode reverseList(ListNode head) {
        ListNode per = null;
        ListNode node = head;
        while (node != null) {
            // 保存节点
            ListNode next = node.next;
            // 将节点的next指针域方向进行反转
            node.next = per;
            // 将两个节点进行右移
            per = node;
            node = next;
        }
        return per;
    }

    public static void main(String[] args) {

    }

}
